package com.freeland.client2009.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.apache.commons.beanutils.converters.BigDecimalConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.freeland.client2009.common.StringUtil;
import com.freeland.client2009.dao.ibatis.GameInfoDAO;
import com.freeland.client2009.dao.ibatis.HotelComputerDAO;
import com.freeland.client2009.dao.ibatis.model.AdState;
import com.freeland.client2009.dao.ibatis.model.ComputerMac;
import com.freeland.client2009.dao.ibatis.model.ComputerPowerInfo;
import com.freeland.client2009.dao.ibatis.model.GameInfo;
import com.freeland.client2009.dao.ibatis.model.NetBarInfo;
import com.freeland.client2009.service.HotelComputerService;
@Service("hotelComputerService")
@Transactional
public class HotelComputerServiceImpl implements HotelComputerService {

	@Autowired
	private HotelComputerDAO hotelComputerDao;
	@Autowired
	private GameInfoDAO gameInfoDao;
	
	public Integer deleteHotelMac(ComputerMac mac) {
		return hotelComputerDao.deleteHotelMac(mac);
	}
	@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
	public List<AdState> getAdStatePage(int pageIndex, int pageSize,
			String userType, String useracct,String username) {
		  return hotelComputerDao.getAdStatePage(pageIndex, pageSize, userType, useracct,username );
	}
	@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
	public Long getAdStateCount(String userType, String useracct,String username) {
		  return hotelComputerDao.getAdStateCount(userType, useracct,username );
	}
	@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
	public List<ComputerMac> getComputerMacPage(int pageIndex, int pageSize,
			String userType, String useracct,String username) {
		 return hotelComputerDao.getComputerMacPage(pageIndex, pageSize, userType, useracct,username );
	}
	@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
	public Long getComputerMacCount(String userType, String useracct,String username) {
		 return hotelComputerDao.getComputerMacCount( userType, useracct,username );
	}
	@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
	public List<ComputerPowerInfo> getComputerUseLogPage(int pageIndex,
			int pageSize, String userType, String useracct,String username, String startDate,
			String endDate,int minute) {
		 return hotelComputerDao.getComputerUseLogPage(pageIndex, pageSize, userType, useracct, username, startDate, endDate,minute);
	}
	@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
	public Long getComputerUseLogCount( String userType, String useracct,String username, String startDate,
			String endDate,int minute) {
		 return hotelComputerDao.getComputerUseLogCount( userType, useracct,username, startDate, endDate,minute);
	}
	@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
	public List<NetBarInfo> getNetBarInfoPage(int pageIndex, int pageSize,
			String userType, String useracct,String username) {
		 return hotelComputerDao.getNetBarInfoPage(pageIndex, pageSize, userType, useracct,username);
	}
	@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
	public Long getNetBarInfoCount(String userType, String useracct,String username){
		return hotelComputerDao.getNetBarInfoCount( userType, useracct,username);
	}

	public Integer updateHotelMac(String useracct, String orignMac,
			String newMac) {
		
		return hotelComputerDao.updateHotelMac(useracct, orignMac, newMac);
	}
	/**
	 * 保存酒店桌面模版页面的推送文件
	 * @param useracct：酒店号
	 * @param name：酒店名称
	 * @param namepy：酒店拼音
	 * @param updateSrvIds：更新节点，1是指的内部节点，3指的电信节点，4，指的是联通节点
	 * @param filePath：文件的路径
	 * @param fileSize：文件的大小
	 */
	public void saveHotelWebFile(String useracct,String name,String namepy,String updateSrvIds,String filePath,String fileSize){
		Date currentDate = new Date();
		GameInfo gameInfo =gameInfoDao.selectByPrimaryKey(useracct);
		String path ="q:\\games\\实用工具（软）\\"+useracct;
		if(gameInfo==null){
			//新增
			gameInfoDao.insertGameInfo(useracct, namepy, name, 10, 10, currentDate, fileSize);
			gameInfoDao.insertMakeGameInfo(useracct, namepy, name, 10, 10, currentDate, fileSize);
			gameInfoDao.insertIdcGroupGameInfo("1", useracct);//1：存储组1
			String[] ids=updateSrvIds.split("_");
			for(String updatesrvId:ids){
			    gameInfoDao.insertUsGameInfo(updatesrvId, useracct, "1", path, 10, 10, fileSize, currentDate);
			}
		}else{
			//更新
			int version =gameInfo.getLocalVersion()+1;
			
			gameInfoDao.updateGameInfo(useracct, version, version,currentDate, fileSize);
			
			gameInfoDao.updateMakeGameInfo(useracct, version, version, currentDate, fileSize);
			
			String[] ids=updateSrvIds.split("_");
			for(String updatesrvId:ids){
			    gameInfoDao.updateUsGameInfoForVersion(updatesrvId, useracct, version, version, fileSize,currentDate);
			}
			
		}
		
	}
	public HotelComputerDAO getHotelComputerDao() {
		return hotelComputerDao;
	}
	public void setHotelComputerDao(HotelComputerDAO hotelComputerDao) {
		this.hotelComputerDao = hotelComputerDao;
	}
	public void setGameInfoDao(GameInfoDAO gameInfoDao) {
		this.gameInfoDao = gameInfoDao;
	}
	
	

}
